import Vue from 'vue'
import VueRouter from 'vue-router'
// import store from '@/store'
// import * as myfun from "@/assets/js/global"
import { getItem, setItem } from '@/utils/CookieUtil'
Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}


/**
 * 静态路由
 */
export const constantRouterMap = [

	// 重定向，每次访问*都定向到首页
	{
		path: '',
		redirect: '/index',
		hidden: true,
	},

	{
		path: '/index',
		meta: {
			icon: null,
			title: "首页",
		},
		hidden: true,
		sort: null,
		component: () => import('@/views/home'),
	},

	{
		path: '/video/:videoId',
		meta: {
			icon: null,
			title: "视频",
		},
		hidden: true,
		sort: null,
		component: () => import('@/views/video'),
	},

	{
		path: '/live/:liveId',
		meta: {
			icon: null,
			title: "直播",
		},
		hidden: true,
		sort: null,
		component: () => import('@/views/live'),
	},
	{
		path: '/personal_center',
		meta: {
			icon: null,
			title: "个人中心",
		},
		hidden: true,
		sort: null,
		component: () => import('@/views/personal_center'),
	},

]
/**
 * 动态路由
 */
export const asyncRouterMap = [


]


const router = new VueRouter({
	mode: "history",
	routes: constantRouterMap,
	// // 控制路由跳转滚动条的位置为最顶部
	scrollBehavior(to, from, savedPosition) {
		// 始终滚动到顶部，y代表距离顶部的距离
		return { y: 0 }
	},
})

const whiteList = ['/admin/login'] // 不重定向白名单

router.beforeEach((to, from, next) => {
	// if (getItem("token")) {
	// 	if (to.path === '/admin/login') {
	// 		next({ path: '/admin/index' })
	// 	} else {
	// 		if (store.state.user.roleList.length === 0) {
	// 			// 拉取用户信息
	// 			getUserInfo(next)
	// 		} else {
	// 			next()
	// 		}
	// 	}
	// } else {
	// 	if (whiteList.indexOf(to.path) !== -1) {
	// 		next()
	// 	} else {
	// 		if (!to.path.match('/admin')) next()
	// 		else next('/admin/login')
	// 	}
	// }
	next()
})

router.afterEach(() => {

});


export default router